//
//  MainTabBarViewController.m
//  LYPhotos
//
//  Created by 美鑫科技 on 16/5/5.
//  Copyright © 2016年 MorpLCP. All rights reserved.
//

#import "MainTabBarViewController.h"
#import "IndexNavigationViewController.h"
#import "IndexViewController.h"
#import "LYNavigationBar.h"

@interface MainTabBarViewController ()

@property (nonatomic, strong) Theme *theme;

@end

@implementation MainTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeDidChanged:) name:@"themeChange" object:nil];
    self.theme = [ThemeManager shareManager].theme;
    [self initSubViewControllers];
}

- (void)initSubViewControllers{
    IndexViewController *indexVC = [IndexViewController new];
    indexVC.isHiddenStatusBar = NO;
    IndexNavigationViewController *indexNav = [[IndexNavigationViewController alloc] initWithRootViewController:indexVC];
    indexNav.barStyle = UIStatusBarStyleLightContent;
    indexNav.tabBarItem.image = [LYImage getImageFromBundleWithName:@"home"];
    [self addChildViewController:indexNav];
}

- (void)setTheme:(Theme *)theme{
    _theme = theme;
    if (theme.themeColor) {
        self.tabBar.barTintColor = theme.themeColor;
    }
    if (theme.themeImage) {
        self.tabBar.backgroundImage = theme.themeImage;
    } else{
        self.tabBar.backgroundImage = nil;
    }
    if (theme.themeImageURL) {
        self.tabBar.backgroundImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:theme.themeImageURL]]];
        self.tabBar.clipsToBounds = YES;
    } else{
        self.tabBar.backgroundImage = nil;
    }
    if (theme.themeTextColor) {
        self.tabBar.tintColor = theme.themeTextColor;
    }
}

- (void)themeDidChanged:(NSNotification *)notifi{
    self.theme = [ThemeManager shareManager].theme;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
